package com.cykj.service.impl;


import com.cykj.bean.Goods;
import com.cykj.bean.PageConfig;
import com.cykj.bean.Tbluser;
import com.cykj.mapper.UserMapper;
import com.cykj.service.IndexService;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class IndexServiceImpl  implements IndexService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<Tbluser> selectUserList() {
        return userMapper.selectUserList();
    }

    @Override
    public String login(String uname, String upwd) {
            Tbluser user =userMapper.login(uname, upwd);
            if (user!=null){
                return "success";
            }
            return "false";
    }

    @Override
    @Transactional //事务处理
    public int regiest(Tbluser tbluser) {
        return userMapper.regiest(tbluser);
    }

    @Override
    public int addLog(String module, String action, String remark) {
        return userMapper.addLog(module, action, remark);
    }

    @Override
    public int selectCount() {
        return userMapper.selectCount();
    }

    @Override
    public List<Tbluser> selectUserList2(RowBounds rowBounds) {
        return userMapper.selectUserList2(rowBounds);
    }

    @Override
    public int deleteUpdate(String uid) {
        return userMapper.deleteUpdate(uid);
    }

    @Override
    public int updateInfo(String uname, String idCard, String address, String uid) {
        return userMapper.updateInfo(uname, idCard, address, uid);
    }

    @Override
    public int selectGoodsCount() {
        return userMapper.selectGoodsCount();
    }

    @Override
    public List<Tbluser> selectGoodsList(RowBounds rowBounds) {
        return userMapper.selectGoodsList(rowBounds);
    }

    @Override
    public Map<String, Object> goodsTables(PageConfig pageConfig) {
        Map<String,Object> map=new HashMap<>();
        map.put("count",userMapper.selectGoodsCount());
        map.put("userList",userMapper.selectGoodsList(new RowBounds((pageConfig.getPage() - 1) * pageConfig.getSize(),pageConfig.getSize())));
        return map;
    }

    @Override
    public int deleteGoods(String id) {
        int deleteState=userMapper.deleteGoods(id);
        if (deleteState==1){
            return 1;
        }
        return 0;
    }

    @Override
    public int updateGoods(Goods goods) {
        int updataGoods=userMapper.updateGoods(goods);
        if (updataGoods==1){
            return 1;
        }
        return 0;
    }


}
